<?php
include_once("../service/userService.php");
include_once("../util/constant.php");

//$fullName, $gender, $email, $dob, $address, $username, $password, $status, $phoneNumber
$username = $_POST["userTitle"];
$password = md5($_POST["userPassword"]);
$fullName = $_POST["userFullname"];

$gender = $_POST["userGender"];
$email = $_POST["userEmail"];
$groups = isset($_POST["selectedPrivilegess"])?$_POST["selectedPrivilegess"]:array();
$staffId = createStaff($fullName, $gender, $email, $username, $password);

if($staffId > 0){
    for($i = 0; $i < count($groups); $i++){
        assignStaffToGroup($staffId,$groups[$i]);
    }
	echo "<script>window.location.href = '../admin/user-detail.php?id=".$staffId."&action=".EDIT_ACTION."';</script>";
}
else
	echo "<script>window.location.href = '../admin/user-detail.php?action=".NEW_ACTION."';</script>";

?>